package zpx.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import zpx.idao.IFileTypeDao;
import zpx.model.FileType;

@SuppressWarnings("restriction")
@Repository("fileTypeDao")
public class FileTypeDao extends HibernateDaoSupport implements IFileTypeDao{

	@Resource
	public void setSuperSessionFactory(SessionFactory sessionFactory) {
		this.setSessionFactory(sessionFactory);
	}
	
	/**
	 * 根据父级id查询下级文件类型列表数据
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<FileType> getFileTypes(String id) {
		if(id==null || "".equals(id)){
            return null;
        }
        StringBuffer sql = new StringBuffer();
        sql.append("from FileType as f where f.pid= :id ");
        Query query = this.getSessionFactory().getCurrentSession().createQuery(sql.toString());
        query.setParameter("id", id);
        List<FileType> datas = query.list();
        return datas;
	}

	/**
	 * 获得文件列表数据
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<FileType> getFileTypesLst(Map<String, String> searchMap) {
		StringBuffer sql = new StringBuffer();
        sql.append("from FileType as f ");
        SQLQuery query = this.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString());
        List<FileType> datas = query.list();
        return datas;
	}
	/**
	 * 根据主键获得文件列表信息
	 */
	@Override
	public FileType getFileType(String id) {
		if(id==null || "".equals(id)){
            return null;
        }
        StringBuffer sql = new StringBuffer();
        sql.append("from Material as m where m.id= :id ");
        SQLQuery query = this.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString());
        query.setParameter("id", id); 
        return (FileType) query.uniqueResult();
	}

	@Override
	public FileType saveOrUpdateFileType(FileType fileType) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void deleteFileType(String id) {
		// TODO Auto-generated method stub
		
	}
	
}
